package com.ssm.zhihu_ssm.service.impl;

import com.ssm.zhihu_ssm.dao.CommentDao;
import com.ssm.zhihu_ssm.entity.Comment;
import com.ssm.zhihu_ssm.entity.CommentReturn;
import com.ssm.zhihu_ssm.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service(value = "commentService")
public class CommentServiceImpl implements CommentService {

    @Autowired
    private CommentDao commentDao;

    @Override
    public List<CommentReturn> getComment(int id ,int state ) {
        List<CommentReturn> comments= commentDao.getComment(id,state);
        System.out.println(comments.size());
        return comments;
    }

    @Override
    public Boolean addgoodNum(int aid) {
        Comment comment= commentDao.findGOODnum(aid);
        System.out.println(comment);
        if (comment!= null)
        {
            int x = comment.getGoodNum()+1;
            comment.setGoodNum(x);
            commentDao.addAgoodNum(comment);
            return  true;
        }
        else {
            return  false;
        }
    }

    @Override
    public boolean insertComment(int aid, int uid, int fromid, String content, int state) {
        Comment comment = new Comment();
        comment.setAID(aid);
        comment.setUID(uid);
        comment.setFromID(fromid);
        comment.setContent(content);
        comment.setState(state);
        commentDao.insertComment(comment);
        return true;
    }


}
